/**
 * Created by Administrator on 2017/3/1 0001.
 */
var loadComplete;
var resource;
var mode;
var pixiStageW=1136;
var pixiStageH=640;
var pixiStage=new PIXI.Stage(0xFF0000);
var PixiMain={
    create:function () {
        var pixi_renderer=PIXI.autoDetectRenderer(pixiStageW,pixiStageH,{antialias:true,transparent:true,resolution:1});

        var div_pixi=document.getElementById('div_2d');
        div_pixi.appendChild(pixi_renderer.view);

        var preload=Preload.create();
        preload.init(pixiStage,pixiStageW,pixiStageH);
        var con_whole=new PIXI.Container();
        pixiStage.addChild(con_whole);

        var game;
        var pageVer=PageVer.create();;
        document.addEventListener('Main_LoadComplete',gameStart);
        function gameStart(e) {
            resource=e.detail.resources;
             // game=Game.create();
             // pixiStage.addChildAt(game.ui,0);
            loadComplete=true;
            resize();
        }

        resize();
        window.onresize = resizeHandlerPIXI;
        function resizeHandlerPIXI() {
            setTimeout(function () {
                 resize();
            },150)
        };
        function resize()
        {

                pixi_renderer.resize(window.innerWidth, window.innerHeight);
                mode='noBorder';
                switch (mode) {
                    case 'exactFit':
                        pixiStage.scale.x = window.innerWidth / pixiStageW;
                        pixiStage.scale.y = window.innerHeight / pixiStageH;
                        break;
                    case 'noBorder':
                        pixiStage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerWidth / pixiStageW) : (window.innerHeight / pixiStageH);
                        pixiStage.scale.y = pixiStage.scale.x;
                        break;
                    case 'noScale':
                        pixiStage.scale.x = 1;
                        pixiStage.scale.y = 1;
                        break;
                    case 'showAll':
                        pixiStage.scale.x = (window.innerHeight / pixiStageH < window.innerWidth / pixiStageW) ? (window.innerHeight / pixiStageH) : (window.innerWidth / pixiStageW);
                        pixiStage.scale.y = pixiStage.scale.x;
                        break;
                }
                pixiStage.x = (window.innerWidth - pixiStageW * pixiStage.scale.x) * .5;
                pixiStage.y = (window.innerHeight - pixiStageH * pixiStage.scale.y) * .5;

                document.getElementById('bala').style.width= pixiStage.scale.x*195+'px';
                document.getElementById('bala').style.height= pixiStage.scale.y*195+'px';
                document.getElementById('bala').style.left= pixiStage.scale.x*470+pixiStage.x+'px';
                document.getElementById('bala').style.top= pixiStage.scale.y*(222)+pixiStage.y+'px';

            if(window.innerWidth<window.innerHeight)
            {
                console.log(pageVer,loadComplete);
                if(pageVer&&loadComplete)
                {
                    pixiStage.addChild(pageVer.ui);

                }
            }
            else
            {
                console.log('game',loadComplete,game)
                if(pageVer&&pageVer.ui.parent)
                {
                    pixiStage.removeChild(pageVer.ui);

                }
                if(loadComplete&&!game)
                {
                    console.log('game')
                    game=Game.create();
                    pixiStage.addChildAt(game.ui,0);
                }
            }

        }
        // var globalID;
        // globalID=
        requestAnimationFrame(animate);
        // cancelAnimationFrame(globalID);
        function animate() {
            requestAnimationFrame(animate);
            pixi_renderer.render(pixiStage);
        }
    }
}